package com.kingyea.mobilepolice.apimanage.dictionary.controller;

import com.kingyea.mobilepolice.apimanage.dictionary.service.DictionaryService;
import com.kingyea.mobilepolice.apimanage.log.OperateType;
import com.kingyea.mobilepolice.apimanage.log.OperationLogAnnotation;
import com.kingyea.mobilepolice.dictionary.bean.Dictionary;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author chenJW
 * @version v1.0.0
 * @description Dictionary 控制层
 * @date Created in 2018-02-27 10:47:05
 */
@Api(value = "字典接口 ", description = " 字典表相关 ")
@RequestMapping(value = "/dictionary")
@RestController
public class DictionaryController {

    private static final Logger LOGGER = LoggerFactory.getLogger(DictionaryController.class);

    @Autowired
    private DictionaryService dictionaryService;

//    /**
//     * 查询全部
//     *
//     * @param
//     * @return
//     */
//    @OperationLogAnnotation(operateName = "查询全部字典值", operateType = OperateType.SELECT, module = "dictionary")
//    @RequestMapping(method = RequestMethod.GET)
//    public Object list() throws Exception {
//        return dictionaryService.list(null);
//    }
//
//    /**
//     * 通过ID查找对象
//     *
//     * @param id
//     * @return
//     */
//    @OperationLogAnnotation(operateName = "通过ID查找字典值", operateType = OperateType.SELECT, module = "dictionary")
//    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
//    public Object detail(@PathVariable Integer id) throws Exception {
//        return dictionaryService.getById(id);
//    }
//
//    /**
//     * 创建
//     *
//     * @param dictionary
//     * @return
//     */
//    @OperationLogAnnotation(operateName = "创建字典值", operateType = OperateType.INSERT, module = "dictionary")
//    @RequestMapping(method = RequestMethod.POST)
//    public Object create(@RequestBody Dictionary dictionary) throws Exception {
//        return dictionaryService.save(dictionary);
//    }
//
//    /**
//     * 更新
//     *
//     * @param dictionary
//     * @return
//     */
//    @OperationLogAnnotation(operateName = "更新字典值", operateType = OperateType.UPDATE, module = "dictionary")
//    @RequestMapping(method = RequestMethod.PUT)
//    public Object update(@RequestBody Dictionary dictionary) throws Exception {
//        return dictionaryService.update(dictionary);
//    }
//
//    /**
//     * 删除
//     *
//     * @param id
//     * @return
//     */
//    @OperationLogAnnotation(operateName = "删除字典值", operateType = OperateType.DELETE, module = "dictionary")
//    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
//    public Object delete(@PathVariable Integer id) throws Exception {
//        return dictionaryService.deleteById(id);
//    }

    /**
     * 获取 type=XXX 的字典值列表
     *
     * @param
     * @return java.lang.Object
     * @author Mr.Lin
     * @date 2018/3/19 18:46
     */
    @ApiOperation(value = "获取 type=XXX 的字典值列表", notes = "", response = Dictionary.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "type", value = "字典类别", required = true, dataType = "String")
    })
    @OperationLogAnnotation(operateName = "获取 type=XXX 的字典值列表", operateType = OperateType.SELECT, module = "dictionary")
    @RequestMapping(value = "/getRootListByType", method = RequestMethod.POST)
    public Object getRootListByType(@RequestBody Map map) throws Exception {
        return dictionaryService.getRootListByType(map);
    }

    /**
     * 根据父ID 获取 某个 节点下的子节点列表
     *
     * @param
     * @return java.lang.Object
     * @author Mr.Lin
     * @date 2018/3/19 18:46
     */
    @ApiOperation(value = "根据父ID 获取 某个 节点下的子节点列表", notes = "", response = Dictionary.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "pid", value = "父级ID", required = true, dataType = "Integer")
    })
    @OperationLogAnnotation(operateName = "获取 id=XXX 的自己字典列表", operateType = OperateType.SELECT, module = "dictionary")
    @RequestMapping(value = "/getSubNodeListByPid", method = RequestMethod.POST)
    public Object getSubNodeListByPid(@RequestBody Map map) throws Exception {
        return dictionaryService.getSubNodeListByPid(map);
    }
}
